package com.base.engine.gui;

import static org.lwjgl.opengl.GL11.*; 

import com.base.engine.font.MADFontManager;
import com.base.engine.font.MADFontRenderer;
import com.base.engine.game.MADGame;
import com.base.engine.graphics.Color4f;
import com.base.engine.graphics.MADRenderer;

public abstract class MADButton extends MADGamingInterface {

	private boolean active = false ; 
	
	public MADButton(MADGame g, float left, float top, float width, float height, String name) {
		super(g, left, top, width, height, name);
	}
	
	public void activate(){
		active = true ; 
	}
	
	public void deactivate(){
		active = false ; 
	}
	
	public boolean isActive(){
		return active ; 
	}

	public void render(){
		if(super.isVisible()){
			glPushMatrix();
				glLineWidth(2);
				if(!isActive())
					MADRenderer.renderRectangle_2f(vertices, new Color4f(0.20f,0.20f,0.20f,1.0f), GL_QUADS);
				else
					MADRenderer.renderRectangle_2f(vertices, new Color4f(0.3f,0.30f,0.30f,1.0f), GL_QUADS);
				MADRenderer.renderRectangle_2f(vertices, new Color4f(0.1f,0.1f,0.1f,1.0f), GL_LINE_LOOP);
				glTranslatef(getLeft(),getTop(),0);
				MADFontRenderer.renderText((getWidth()-vertices.NAME.length()*10)/2, (getHeight()-25)/2, 
									this.vertices.NAME, MADFontManager.getUFontByName(MADFontManager.MENU_TEXT)); 
			glPopMatrix();
		}
	}
	
	public abstract void onClick() ; 
	
	public boolean isInSensitiveeArea(float x, float y){
		return (isVisible() && (x>=getLeft() && x<=getLeft()+getWidth()) && (y>=getTop() && y<=getTop()+getHeight())); 
	}
	
}
